add_library(libcustomer lib.cpp)
# NOTE:what is this
add_library(domifair::libcustomer ALIAS libcustomer)
set_target_properties(libcustomer PROPERTIES OUTPUT_NAME customer)
target_compile_features(libcustomer PUBLIC cxx_std_20)
target_include_directories(libcustomer
  PUBLIC
  $<INSTALL_INTERFACE:include>
  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)
# SEE: https://github.com/Microsoft/cpprestsdk/issues/230
target_compile_definitions(libcustomer PUBLIC _TURN_OFF_PLATFORM_STRING) 
set_target_properties(libcustomer PROPERTIES CXX_EXTENSIONS OFF)
#target_compile_options(libcustomer PRIVATE ${BASE_COMPILE_FLAGS}) # disable this line maybe 
#end
add_executable(customer main.cpp)
target_compile_features(customer PRIVATE cxx_std_20)
target_link_libraries(customer PRIVATE libcustomer)
set_target_properties(customer PROPERTIES CXX_EXTENSIONS OFF)
#target_compile_options(customer PRIVATE ${BASE_COMPILE_FLAGS})
#end

# install
include(GNUInstallDirs) # check if works on windows wsl

install(
  TARGETS libcustomer customer
  EXPORT CustomerTargets
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
#end
install(
  DIRECTORY ${PROJECT_SOURCE_DIR}/include/ #NOTE: last slash is important here
  DESTINATION include
)
#end

if (NOT CONAN_EXPOERTED)
  install(
    EXPORT CustomerTargets
    FILE CustomerTargets.cmake
    NAMESPACE domifair::
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Customer
  )# cmake module target
    configure_file(
      ${PROJECT_SOURCE_DIR}/cmake/CustomerConfig.cmake.in
      CustomerConfig.cmake @ONLY            
    )
  #end
  include(CMakePackageConfigHelpers)
  write_basic_package_version_file(
    CustomerConfigVersion.cmake
    VERSION ${PACKAGE_VERSION}
    COMPATIBILITY AnyNewerVersion
  )
  #end
  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CustomerConfig.cmake
    ${CMAKE_CURRENT_BINARY_DIR}/CustomerConfigVersion.cmake
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/Customer
  )
endif()

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CustomerConfig.cmake
  ${CMAKE_CURRENT_BINARY_DIR}/CustomerConfigVersion.cmake
  DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Customer
)
#end

# Exporting
export(
  TARGETS libcustomer customer
  NAMESPACE domifair::
  FILE CustomerTargets.cmake
)

set(CMAKE_EXPORT_PACKAGE_REGISTRY ON)
export(PACKAGE domifair)

# Packaging support
set(CPACK_PACKAGE_VENDOR "Authors")
set(CPACK_PACKAGE_CONTACT "author@example.com")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
  "library and app for customer microservice"
)
# packaging version 
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})

# used by installers like NSIS , .msi format?
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/readme.md")

list(APPEND CPACK_GENERATOR TGZ ZIP)
if(UNIX)
  find_program(DPKG_PROGRAM dpkg)
  if (DPKG_PROGRAM)
    list(APPEND CPACK_GENERATOR DEB)
    set(CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS} libcpprest2.10 (>= 2.10.2-6)")
    set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
  else()
    message(STATUS "rpmbuild not found - won't be able to create RPM package")
  endif()
endif()

set(CPACK_SOURCE_IGNORE_FILES /.git /dist /.*build.* /\\\\.DS_Store) # packaging ignore file and dir

include(CPack)

# TODO: conan support? -- maybe remove
